using System;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
using resharperupdate.core.dto;
using resharperupdate.core.dto.impl;

namespace resharperupdate.core.services.impl
{
    public class ViEmuParser : IViEmuParser
    {
        public IViEmuBuild parse(string html)
        {
            var build = new ViEmuBuild();
            var doc = new HtmlDocument();
            //doc.OptionOutputAsXml = true;
            doc.LoadHtml(html);
            build.url =            
                doc.DocumentNode.SelectSingleNode("//html/body/div/div/div[2]/div/div/div[2]/div/p/a").Attributes["href"].Value;
            build.version = Regex.Match(build.url, "\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}").ToString();
            return build;
        }
    }
}